﻿/* ------------------------------------------------------------------------ */
/* TheNewCoders Scripting (TNCScripting) v1.0                               */
/* ------------------------------------------------------------------------ */
/* A scripting engine for C# that is even compatible with XNA for Xbox360.  */
/* Copyright (C) 2010 Prageeth Silva <prageeth@thenewcoders.com>            */
/*                                                                          */
/* This program is free software; you can redistribute it and/or            */
/* modify it under the terms of the GNU General Public License              */
/* as published by the Free Software Foundation; either version 2           */
/* of the License, or (at your option) any later version.                   */
/*                                                                          */
/* This program is distributed in the hope that it will be useful,          */
/* but WITHOUT ANY WARRANTY; without even the implied warranty of           */
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the            */
/* GNU General Public License for more details.                             */
/*                                                                          */
/* You should have received a copy of the GNU General Public License        */
/* along with this program; if not, write to the Free Software              */
/* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,               */
/* MA  02110-1301, USA. OR visit <http://www.gnu.org/licenses/gpl-2.0.html> */
/* ------------------------------------------------------------------------ */

using System;
using TNCScripting;

namespace ScriptingTest
{
    class Program
    {
        /// <summary>
        /// Program Entry point
        /// </summary>
        static void Main(string[] args)
        {

            // Create a new script from the specified (testscript.tnc) file
            Script script = new Script("testscript.tnc");
            script.LoadFile();  // Load the file before any functions can be evaluated

            TestClass1 testobj = new TestClass1();
            ReturnValue val = script.EvaluateFunction("TestFunction1", testobj, 2);
            // check if any objects were returned by the called function
            if (val.Valid)
            {
                Console.WriteLine("returned: " + val.Object.ToString());
            }

            Console.WriteLine("Press ENTER to exit...");
            string input = Console.ReadLine();

        }
    }
    
    /// <summary>
    /// First test class.
    /// </summary>
    public class TestClass1
    {

        // To display PROPERTY (needs to be public) access by the script
        public TestClass2 SampleProperty
        {
            get { return this.sample; }
            set { this.sample = value; }
        }
        private TestClass2 sample = new TestClass2();

        // To display METHOD (needs to be public) access by the script
        public double TestMethod(double x1, string x2)
        {
            Console.WriteLine(string.Format("TestClass1.TestMethod invoked: param1[{0}] param2[{1}]", x1, x2));
            return x1 + 1;
        }

    }

    /// <summary>
    /// Secind test class
    /// </summary>
    public class TestClass2
    {

        // To display METHOD (needs to be public) access by the script
        public string AnotherTestMethod(double x1, string x2)
        {
            Console.WriteLine(string.Format("TestClass2.TestMethod invoked: param1[{0}] param2[{1}]", x1, x2));
            return string.Format("**CASE MODIFIED** [{0}]", x2.ToUpper());
        }

    }

}
